<template>
  <div class="openclass-list maxW">
    <div class="single-selection common-cascader">
      <div class="course-sub clear">
        <span>学段</span>
        <div class="course-li clear">
          <label
            v-for="(item, index) of orgLevel2"
            :key="item.xk_id"
            @change="getGradeData(index, item.xk_id)"
          >
            <input
              type="radio"
              name="course2"
              :checked="index == sectionChecked"
            />
            <span>{{ item.name }}</span>
          </label>
        </div>
      </div>
      <div class="course-sub clear">
        <span>科目</span>
        <div class="course-li clear">
          <label
            v-for="(item, index) of orgSubject"
            :key="item.xk_id"
            @change="subjectChange(index, item.xk_id)"
          >
            <input
              type="radio"
              name="course4"
              :checked="index == subjectChecked"
            />
            <span>{{ item.name }}</span>
          </label>
        </div>
      </div>
    </div>
    <div class="course-video-con">
      <ul class="course-video-list clear">
        <li
          class="course-video-li box"
          v-for="(item, index) of videoListData"
          :key="index"
        >
          <div class="video-thumbnail">
            <a @click="goToVideoDetail(item.xk_id, item.picture)">
              <img
                :src="BASE_URL + item.picture"
                :onerror="errorImg"
                alt="默认封面"
              />
            </a>
          </div>
          <div class="video-creater-info">
            <a
              @click="goToVideoDetail(item.xk_id, item.picture)"
              :title="item.videoTitle"
              >{{ item.videoTitle }}</a
            >
            <div class="teacher-info">
              <div>
                <span class="teacher-name">{{
                  item.stage_name +
                  (item.subject_name
                    ? `/${item.subject_name}`
                    : item.subject_name)
                }}</span>
              </div>
              <div>
                <i class="el-icon-video-play"></i>
                <strong>{{ item.clicks }}</strong>
              </div>
            </div>
          </div>
        </li>
      </ul>
      <div class="pageBox">
        <el-pagination
          v-if="total_number > videoParam.page_size"
          @current-change="change_page"
          :page-size="videoParam.page_size"
          :current-page="videoParam.page_index"
          layout="total,prev, pager, next,jumper"
          :total="total_number"
        ></el-pagination>
      </div>
    </div>
    <div class="dependent" v-if="placeholder">
      <i class="ipng image_state01"></i>
      <p>还没发现任何相关的公开课哦~</p>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    userData: {},
  },
  components: {},
  data() {
    return {
      placeholder: false,
      videoParam: {
        keyword: this.$route.query.keyword,
        stageId: null, // 学段
        subjectId: null,
        page_index: 1,
        page_size: 16,
      },
      total_number: 0,
      videoListData: [],
      orgSubject: [],
      orgLevel2: [],
      sectionChecked: 0,
      subjectChecked: 0,
      errorImg:
        'this.src="' +
        require("./../../../assets/images/fengmian-tupian.png") +
        '"',
    };
  },
  created() {
    this.getOrgLevel2();
    this.getSubject();
    this.getVideoData();
  },
  mounted() {},
  computed: {
    user_login_id() {
      return this.userData.userInfo.id ? this.userData.userInfo.id : 0;
    },
  },
  methods: {
    getOrgLevel2() {
      let success = (data) => {
        this.orgLevel2 = data.data;
        this.orgLevel2.unshift({ xk_id: null, name: "全部" });
      };
      this.$ajax.get("/api/xkvideo/stages_list", {
        func: { success: success },
      });
    },
    getSubject() {
      let success = (data) => {
        this.orgSubject = data.data;
        this.orgSubject.unshift({ xk_id: null, name: "全部" });
      };
      this.$ajax.get("/api/xkvideo/subjects_list", { func: { success } });
    },
    getGradeData(index, xk_id) {
      this.sectionChecked = index;
      this.videoParam.stageId = xk_id;
      this.videoParam.page_index = 1;
      this.getVideoData();
    },
    subjectChange(index, xk_id) {
      this.subjectChecked = index;
      this.videoParam.subjectId = xk_id;
      this.videoParam.page_index = 1;
      this.getVideoData();
    },
    getVideoData() {
      let success = (res) => {
        this.videoListData = res.data.data;
        this.total_number = parseInt(res.data.data_sum);
        this.placeholder = this.videoListData.length === 0 ? true : false;
      };
      this.$ajax({
        url: "/api/xkvideo/video_list",
        method: "get",
        params: this.videoParam,
        func: { success: success },
      });
    },
    change_page(val) {
      this.videoParam.page_index = val;
      this.getVideoData();
    },

    goToVideoDetail(theId, picture) {
      if (this.user_login_id == 0)
        return this.$message.warning("先登陆个人账号，才能进行此操作哦~");
      this.$router.push({
        name: "videoDetail",
        query: { id: theId },
        params: { pic: picture },
      });
    },
  },
};
</script>
<style lang="scss">
.carousel-part {
  .caurse-carousel {
    display: inline-block;
    width: 860px;
    height: 400px;

    .el-carousel {
      border-radius: 3px;
    }

    .el-carousel__container {
      width: 860px;
    }

    img {
      height: 100%;
    }

    .el-carousel__indicator .el-carousel__button {
      width: 8px;
      height: 8px;
      border-radius: 50%;
    }
  }

  .popularity-list {
    display: inline-block;
    width: 320px;
    background-color: #fff;

    .humantitle {
      padding: 5px 8px;
      border-radius: 2px;
      font-size: 14px;
      color: #fff;
      background-color: #338efc;
    }

    .el-card__header {
      padding: 25px 10px;
      margin: 0 8px;
      border-bottom: solid 2px #e5e5e5;
    }

    .el-card__body {
      height: 299px;
      padding: 15px 20px 20px;
    }

    .humanItem {
      padding: 5px 0;
    }

    .humanItem i {
      border-radius: 4px;
    }

    .humanItem a {
      display: inline-block;
      width: 80%;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }

    .humanItem:hover {
      background-color: #effaff;
    }

    .humanItem:hover > a {
      color: #348efc;
    }

    .humanNun {
      display: inline-block;
      width: 20px;
      height: 20px;
      line-height: 20px;
      text-align: center;
      color: #ffffff;
      background: #d2d2d2;
      margin-right: 10px;
    }

    .humanNun.yellowC {
      background: #f2b732;
    }
  }
}

.course-video-con {
  margin: 20px 0 40px;
}

.filter-nav {
  .el-button {
    font-size: 16px;
    color: #000;
  }

  .el-icon-sort-down {
    margin-left: 5px;
  }

  .cut {
    margin: 0 20px 0 10px;
    color: #d2d2d2;
  }

  .blueC {
    color: #338efc;
  }
}

.course-video-list {
  .course-video-li {
    float: left;
    width: 290px;
    border-radius: 3px;
    box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin: 0 13px 20px 0;
    background: #fff;

    -moz-transition: all 0.35s ease-in;
    -webkit-transition: all 0.35s ease-in;
    -o-transition: all 0.35s ease-in;
    transition: all 0.35s ease-in;
    position: relative;

    .course-video-li .video-creater-info > a,
    .course-video-li .video-creater-info > p {
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }
  }

  .course-video-li:hover {
    -webkit-box-shadow: 0 6px 7px 0 rgba(0, 0, 0, 0.1);
    -moz-box-shadow: 0 6px 7px 0 rgba(0, 0, 0, 0.1);
    box-shadow: 0 6px 7px 0 rgba(0, 0, 0, 0.1);
  }

  .course-video-li .video-thumbnail {
    height: 140px;
    display: block;
    overflow: hidden;
  }

  .course-video-li .video-thumbnail a,
  .course-video-li .video-thumbnail img {
    width: 100%;
    height: 100%;
    vertical-align: top;
  }

  .video-thumbnail a {
    position: relative;
  }

  .video-thumbnail a::after {
    content: "";
    opacity: 0;
    background: linear-gradient(
      180deg,
      rgba(0, 0, 0, 0.01) 2%,
      rgba(0, 0, 0, 0.2)
    );
    transition: opacity 0.4s ease-in-out;
    position: absolute;
    top: 2px;
    left: 0;
    width: 100%;
    height: 140px;
  }

  .video-thumbnail:hover > a:after {
    opacity: 1;
  }

  .course-video-li .video-creater-info {
    padding: 0 10px 10px;
    background: #ffffff;
  }

  .course-video-li .video-creater-info > a {
    font-size: 14px;
    color: #020202;
    line-height: 20px;
    padding-top: 13px;
    display: block;
    cursor: pointer;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .course-video-li .video-creater-info .course-video-li:hover {
    box-shadow: 0 6px 7px 0 rgba(0, 0, 0, 0.1);
  }

  .course-video-li:nth-of-type(4n) {
    margin: 0 0 18px 0;
  }

  .teacher-info {
    margin-top: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    > div {
      // height: 25px;
      // line-height: 25px;
    }
    .teacher-name {
      color: #999;
      display: inline-block;
      width: 153px;
      height: 25px;
      line-height: 25px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .acatar_img {
      display: inline-block;
      width: 25px;
      height: 25px;
      -moz-border-radius: 50%;
      border-radius: 50%;
      overflow: hidden;
      margin-right: 5px;
    }
    .el-icon-video-play {
      font-size: 18px;
      color: #b2c5db;
      vertical-align: middle;
    }

    strong {
      margin-left: 5px;
      vertical-align: middle;
    }
  }
  .category {
    padding-top: 15px;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.is-nice {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-block;
  width: 20px;
  height: 20px;
  background: url("../../../assets/images/openclassQuality.png") no-repeat;
}

.dependent {
  background-color: #fff;
  text-align: center;
  overflow: hidden;
  margin-bottom: 50px;
  padding-top: 30px;

  p {
    color: #999;
    margin: 40px 0;
  }
}

.single-selection {
  .course-sub {
    font-size: 14px;
    line-height: 19px;
    margin-bottom: 10px;
  }

  .course-sub > span {
    display: block;
    float: left;
    color: #666666;
    width: 60px;
    overflow: hidden;
    height: 19px;
    text-align: left;
  }

  .course-sub:last-of-type {
    margin-bottom: 0;
  }

  .course-li {
    margin-left: 60px;
    min-height: 29px;
  }

  .course-li > label {
    float: left;
    color: #000000;
    cursor: pointer;
    margin: 0 3.7735849057% 10px 0;
  }

  .course-li > label > input:checked + span {
    color: #348efc;
  }

  .course-li > label input {
    display: none;
  }

  .course-li > label:hover {
    color: #61a4f5;
  }
}
</style>